<?php
namespace view;

class BlogView {
    private $m_blogHeader = "";
    private $m_blogText = "";
    private $m_updatedBlogText = "";
    private $m_updatedBlogHeader = "";
    private $m_blogPostStatusMessage ="";
    private $blogModel;

    /**
    * @param object \controller\BlogController $blogModel
    */
    public function __construct(\model\BlogModel $blogModel)     {
        $this->blogModel = $blogModel;
    }


    /**
    * @return boolean
    *
    * om användaren vill lägga till ny post
    */
    public function wantsToAddPost() {
        if (isset($_GET[$this->blogModel->applicationModel->m_addBlogPostURL]) ) {
            return true;
        } else {
              return false;
        }
    }


    /**
    * @return boolean
    */
    public function hasNewBlogInput() {
        if (isset($_POST[$this->blogModel->applicationModel->m_postBlogHeader]) ) {
            return true;
        } else {
              return false;
        }
    }


    /**
    * @return array
    */
    public function getNewBlogPostInput() {
        $blogHeader = $_POST[$this->blogModel->applicationModel->m_postBlogHeader];
        $blogText = $_POST[$this->blogModel->applicationModel->m_postBlogText];
        return array($blogHeader, $blogText);
    }


    /**
    * @param string \controller\BlogController $blogHeader
    * @param string \controller\BlogController $blogText
    */
    public function setNewBlogPostInput($blogHeader, $blogText) {
        $this->m_blogHeader = $blogHeader;
        $this->m_blogText = $blogText;
    }


    /**
    * @return array
    */
    public function returnNewBlogInput() {
        return array($this->m_blogHeader, $this->m_blogText);
    }


    /**
    * @param string \controller\BlogController $type
    * @param string \controller\BlogController $statusCode
    *
    * sätter status medelande
    */
    public function setBlogStatusMessage($type, $statusCode) {
        if($statusCode==1) {
            $statusMessage =  "Your post headline must have at least ". $this->blogModel->applicationModel->m_minNumberBlogHeader ." characters!" ;

        } else if ($statusCode==2) {
            $statusMessage =  "<br>Your post must have at least ". $this->blogModel->applicationModel->m_minNumberBlogText ." characters!" ;

        }  else if ($statusCode==3) {
            if ($type == $this->blogModel->applicationModel->m_newType) {
                $blogText = $this->getNewBlogPostInput();
            } else if($type == $this->blogModel->applicationModel->m_updateType) {
                $blogText = $this->getupdatedBlogPostInput();
            }
            $statusMessage =  "<br>Your post can only have ". $this->blogModel->applicationModel->m_maxNumberBlogText ." characters!<br>Number of characters in post are ". (strlen($blogText[1]));

        }  else if ($statusCode==4) {
              $statusMessage =  "Your post must have at least 6 characters!" ;

        } else if ($statusCode==5) {
            if ($type == $this->blogModel->applicationModel->m_newType) {
                $blogText = $this->getNewBlogPostInput();
            } else if($type == $this->blogModel->applicationModel->m_updateType) {
                $blogText = $this->getupdatedBlogPostInput();
            }
            $statusMessage =  "Your post can only have ". $this->blogModel->applicationModel->m_maxNumberBlogText ." characters!<br>Number of characters in post are ". (strlen($blogText[1]));

        } else if ($statusCode==6) {
            $statusMessage =  "Your post contains invalid characters! <br>Invalid characters have been removed." ;
        }  else {
             $statusMessage =  "";
        }

        $this->m_blogPostStatusMessage .= $statusMessage;
    }


    /**
    * @return string
    */
    public function returnBlogStatusMessage() {
        return $this->m_blogPostStatusMessage;
    }


    /**
    * @return boolean
    *
    * körs om användaren vill uppdatera Blogpost
    */
    public function wantsToEditBlogPost() {
       if (isset($_GET[$this->blogModel->applicationModel->m_editBlogPostURL]) ) {
            return true;
       } else {
            return false;
       }
    }


    /**
    * @return bolean
    *
    * körs om användaren vill ta bort blogpost
    */
    public function wantsToRemoveBlogPost() {
        if (isset($_GET[$this->blogModel->applicationModel->m_deleteBlogPostURL]) ) {
            return true;
        } else {
            return false;
        }
    }


    /**
    * @return string $id
    *
    * Returnerer blog-postID
    */
    public function returnBlogPostId() {
        if (isset($_GET[$this->blogModel->applicationModel->m_editBlogPostURL])){
            $id = $_GET[$this->blogModel->applicationModel->m_editBlogPostURL];
            return $id;
        } else if(isset($_GET[$this->blogModel->applicationModel->m_deleteBlogPostURL])) {
            $id = $_GET[$this->blogModel->applicationModel->m_deleteBlogPostURL];
            return $id;
        }
    }


    /**
    * @return boolean
    */
    public function hasUpdatedBlogPostInput() {
        if (isset($_POST[$this->blogModel->applicationModel->m_postUpdatedBlogText]) ) {
            return true;
        } else {
            return false;
        }
    }


    /**
    * @return array
    */
    public function getUpdatedBlogPostInput() {
          $blogHeader = $_POST[$this->blogModel->applicationModel->m_postUpdatedBlogHeader];
          $blogText = $_POST[$this->blogModel->applicationModel->m_postUpdatedBlogText];
          return array($blogHeader, $blogText);
    }


    /**
    * @param string \controller\BlogController $blogHeader
    * @param string \controller\BlogController $blogText
    */
    public function setUpdatedBlogPost($blogHeader, $blogText) {
        $this->m_updatedBlogHeader = $blogHeader;
        $this->m_updatedBlogText = $blogText;
    }


    /**
    * @return array
    */
    public function returnUpdatedBlogInput() {
        return array($this->m_updatedBlogHeader, $this->m_updatedBlogText);
    }


}

